<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/views/global/taglibs.jsp" %>
<link rel="stylesheet" type="text/css" href="static/css/module/seller.css" />
<link href="static/css/page/submitStore.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="static/javascript/global/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="static/javascript/global/ueditor/ueditor.all.js"></script>
<style type="text/css">
	.main-md DIV.form-group{border-bottom: 1px dashed #ddd;}
	.grid .g-u {
	   display:inline-block
	}
	.maincontent{background: #e4e7ea;} 
	.text-muted {
	    text-transform: uppercase;
	    font-size: 10px;
    }
    .results-list .media {
    border-bottom: 1px solid #eee;
	}
	
	.results-list .media-object {
	    width: 125px;
	    margin-right: 10px;
	}
	
	.results-list .filename {
	    margin: 0;
	    font-size: 16px;
	}
	
	.results-list .media-body {
	    line-height: 18px;
	}
	
</style>
<div class="panel panel-info">
      <div class="panel-heading">  
        <h4>添加配置</h4> <div id="msg"></div>
      </div>  
      <div class="panel-body"> 
            <div>
 	 			<form class="form-horizontal validate" role="form" id="itemForm" name="itemForm" enctype="multipart/form-data">
 	 				<input type="hidden" name="id" value="${entity.id }"/>
 	 				<input type="hidden" id="toAddType" name="toAddType" value="${toAddType }"/>
 	 				<input type="hidden" name="status" value="${entity.status }"/>
					   <div class="form-group">
					        <label for="title" class="col-sm-1 control-label">标题</label>
					        <div class="col-md-3">
					          <input type="text" class="form-control" id="title" name="title" required="标题不能为空" value="${entity.title }">
					        </div>
					        <label for="disType" class="col-sm-1 control-label">场景</label>
					        <div class="col-md-3">
					         <select id="disType" name="disType" class="form-control" data-placeholder="选择一个场景">
			                  <option value=""></option>
			                  <c:forEach var="item" items="${distTypes}">
		  							<option value="${item.dictValue }">${item.dictName }</option>
		  						</c:forEach>
			                 </select>
			                 </div>
			                 <label for="sort" class="col-sm-1 control-label">排序</label>
							 <div class="col-md-3">
							      <input type="text" class="form-control" id="sort" name="sort" value="${entity.sort }"/>
							 </div>
					  </div>
					  <div class="form-group">
					        <label for="title" class="col-sm-1 control-label">链接</label>
					        <div class="col-md-11">
					          <input type="text" class="form-control" id="path" name="path" value="${entity.path }">
					        </div>
					  </div>
					  <div class="form-group">
					    <label for="logoUrl" class="col-sm-1 control-label">图片</label>
					    <input type="hidden" id="fileId" name="fileId" value="${entity.fileId }"/>
					    <div class="col-sm-11">
					    	<div class="row">
					    		<div class="addImageArea col-xs-3" >
					              <input id="addImageFile" name="addImage" class="addImage" type="file" accept="img/*"/>
					              <img class="addImageIcon" src="static/images/page/submitCommodity/photoAddIcon.png"/>
					            </div>
					            <ul class="storeImageAdded col-xs-9">
					            	<c:if test="${empty entity.fileId }">
					            	<li class="addedStoreImage"><img width='270px' height='270px' src="static/images/module/image_upload/imageAddBlank.png" blank="true"/>
					            	</c:if>
					                <c:if test="${not empty entity.fileId }">
					                     <li class="addedStoreImage"><img width='270px' height='270px' src="${fileServerBasePath }download/${entity.fileId  }" blank="false"/>
					                     <div class="storeImgDeleteIcon" onclick='deleteImage(this)'></div></li>
					                </c:if>
					            </ul>
					    	</div>
					    </div>
					  </div>
					   <div class="form-group">
					    <label for="introduction" class="col-sm-1 control-label">描述</label>
					    <div class="col-sm-11">
					    <script id="container" name="comments" type="text/plain">${entity.comments}</script>
					    </div>
					  </div>
			      </form>
			 </div>
      </div>  
      <div class="panel-footer">
      	<div class="row">
      		<div class="col-xs-1">
      		</div>
      		<div class="col-xs-2">
      			<button type="button" class="btn btn-success btn-lg" onclick="javascript:addNode()">保 存</button>
      		</div>
      		<div class="col-xs-9">
      			<a href="admin/displayPicConfigList"><button type="button" class="btn btn-default btn-lg">返 回</button></a>
      		</div>
      	</div>
      </div>  
 </div>
<script type="text/javascript">
$(document).ready(function(){
	$("#disType").val('${entity.disType}');
	
	$("#addImageFile").on("change", function(){
		var target = this;
		if("" != $.trim($(target).val())){
			if(0 == $(".storeImageAdded").find("IMG[blank='true']").length){
				alert("PLEASE DELETE THIS BEFORE UPLOAD NEW!");
				return false;
			}
			$("#itemForm").goAjax({
				url:"/upload",
				semantic:false,
				data:{},
				success: function(jsonData) {
					if("SUCCESS" == jsonData.state){
						var imgObj = $(".storeImageAdded").find("IMG[blank='true']").eq(0);
						$(imgObj).attr("src", jsonData.url);
						$(imgObj).attr("blank", 'false');
						$(imgObj).after('<div class="storeImgDeleteIcon" onclick="deleteImage(this,'+$(imgObj).attr("index")+')"></div>');
						$("#fileId").val(jsonData.fileId);
					}
					$(target).val("");
				}
			});
		}
	});
});

function addNode(){
	var validator = $("#itemForm").validate({meta:"validate"});
	if(validator.form()){
		$("#itemForm").goAjax({semantic: false, checkLogin: false,
			url: "admin/displayPicConfigList/doAdd",
			data:{},
			success: function(jsonData) {
				window.location="admin/displayPicConfigList?toDisType="+$("input[name=toAddType]").val();
			}
		});
	}
}
function deleteImage(target){
	var imgObj = $(target).prev();
	$(imgObj).attr("blank", "true");
	$(imgObj).attr("src", "static/images/module/image_upload/imageAddBlank.png");
	$(target).remove();
	$("#fileId").val("");
}
UE.getEditor('container').addListener('ready', function() {
    //this是当前创建的编辑器实例
})

</script>
